import router from './index'
import store from "../store"

router.beforeEach((to, from,next) => {
    // 判断是否去登录页
    if(to.name === "login") return next();
    // 判断是否携带个人信息 是否存在token
    let userinfo = store.state.employee.userinfo;
    // 信息不存在
    if(!userinfo){
        userinfo = JSON.parse(localStorage.getItem("userinfo"));
        // 本地是否存在
        if(userinfo){
            store.commit("employee/setUserinfo",userinfo)
        }else {
            return next("/login");
        }
    }
    next()
})